import { addOneProblem, updateOneProblem, deleteProblems, lookProblem, lookProblemById } from '@/api/problem'

const getDefaultState = () => {}

const state = getDefaultState()

const mutations = {}

const actions = {
  // 条件查询
  async lookProblem({ state }, problem) {
    return new Promise((resolve, reject) => {
      lookProblem(problem)
        .then((response) => {
          resolve(response)
        })
        .catch((error) => {
          reject(error)
        })
    })
  },
  // 条件查询
  async lookProblemById({ state }, data) {
    return new Promise((resolve, reject) => { 
      lookProblemById(data.id)
        .then((response) => {
          resolve(response)
        })
        .catch((error) => {
          reject(error)
        })
    })
  },
  // 添加一条试题
  async addOneProblem({ commit, state }, problem) {
    return new Promise((resolve, reject) => {
      addOneProblem(problem)
        .then((response) => {
          resolve(response)
        })
        .catch((error) => {
          reject(error)
        })
    })
  },
  // 修改试题
  async updateOneProblem({ commit, state }, problem) {
    return new Promise((resolve, reject) => {
      updateOneProblem(problem)
        .then((response) => {
          resolve(response)
        })
        .catch((error) => {
          reject(error)
        })
    })
  },
  // 批量删除试题
  async deleteProblems({ commit, state }, ids) {
    return new Promise((resolve, reject) => {
      deleteProblems(ids)
        .then((response) => {
          resolve(response)
        })
        .catch((error) => {
          reject(error)
        })
    })
  },
}

export default {
  namespaced: true,
  state,
  mutations,
  actions,
}
